<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>Title</title>
</head>
<body>
<script>
  function getresult()
  {
    var num1=document.getElementById("num1").value;
    var sig=document.getElementById("sig").value;
    var num2=document.getElementById("num2").value;
    n1 = parseFloat(num1);
    n2 = parseFloat(num2);
    if(sig=="/"&& num2=="0")
    {
      document.getElementById("result").value = "除数不能为0";
    }else if (isNaN(num1)==true||isNaN(num2)==true){
      //isNaN()返回为数字输出false,返回为其他值输出true
      document.getElementById("result").value = "输入参数必须为数字";
    } else
    {

      switch (sig) {
        case "+":
          document.getElementById("result").value = n1+n2;
          break;
        case "-":
          document.getElementById("result").value =n1-n2;
          break;
        case "*":
          document.getElementById("result").value =n1*n2;
          break;
        case "/":
          document.getElementById("result").value =n1/n2;
          break;

      }
    }

  }
</script>
<h1>我的计算机</h1>
<hr color="red"><br><br>
<form action="" method="get">
  请输入第一个数：<input type="text" name="firstnum" id="num1"><br><br>
  请选择运算方式：
  <select name="sig" id="sig" >
    <option value="+">+</option>
    <option value="-">-</option>
    <option value="*">*</option>
    <option value="/">/</option>
  </select>
  <br><br>
  请输入第二个数：<input type="text" name="secondnum" id="num2"><br><br>
  <button type="button" onclick="getresult()">计算</button>
  <button type="reset" > 重置 </button><br><br>
  结果：<input type="text" name="result" id="result"  >
</form>
</body>
</html>